package com.pms.controller;

import java.io.IOException;
import java.util.List;

import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pms.domain.Project;
import com.pms.service.ProjectService;


/** 
* @ClassName: ProjectController 
* @Description:  项目控制器
* @author ZZW
* @date 2016年12月6日 下午2:32:09 
*  
*/
@Controller
@RequestMapping("/project")
public class ProjectController {

	@Autowired
	private ProjectService projectService;

	/**
	 * 获取所有对象
	 * @author ZZW
	 * @return  String
	 * @throws IOException
	 */
	@RequestMapping(value = "/query.pfv",method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public String getProjects() throws IOException {
		List<Project> projectList = projectService.getAll() ;
		return new String(JSONObject.valueToString(projectList).toString().getBytes(),"utf-8");
	}
	
	/**
	 * 获得单个对象
	 * @author ZZW
	 * @param id
	 * @return String
	 * @throws IOException
	 */
	@RequestMapping(value = "/getById.pfv",method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public String getProjectById(@RequestParam(value="id")Integer id) throws IOException {
		Project project = projectService.selectByPrimaryKey(id);
		
		return new String(JSONObject.valueToString(project).toString().getBytes(),"utf-8");
	}
	
	@RequestMapping(value = "/insert.pfv",method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void insertProject(@RequestParam(value="project")Project project) throws IOException {
		projectService.insertProject(project);
	}
	
	/**
	 * 更新
	 * @author ZZW
	 * @param project
	 * @throws IOException
	 */
	@RequestMapping(value = "/update.pfv",method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void updateProject(@RequestParam(value="project")Project project) throws IOException {
		projectService.updateByPrimaryKey(project);
	}
	
	/**
	 * 删除
	 * @author ZZW
	 * @param id
	 * @throws IOException
	 */
	@RequestMapping(value = "/delete.pfv",method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void deleteProject(@RequestParam(value="id")Integer id) throws IOException {
		projectService.deleteProject(id);
	}
	
	
}
